package com.itheima.app.controller;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.app.manager.VideoManager;
import com.itheima.service.mongo.VisitorService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@RestController
public class VideoController {
    @Autowired
    private VideoManager videoManager;


    @GetMapping("/smallVideos")//查询推荐小视频
    public ResponseEntity findSmallVideos(@RequestParam(value = "page",defaultValue = "1")Integer pageNum,
                                          @RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize){
        Long userId = UserHolder.get().getId();
        PageBeanVo pageBeanVo=videoManager.findSmallVideos(userId,pageNum,pageSize);
        return ResponseEntity.ok(pageBeanVo);
    }

    @PostMapping("/smallVideos")//发布小视频
    public void addSmallVideos(MultipartFile videoThumbnail	,MultipartFile videoFile) throws IOException {
        Long userId=UserHolder.get().getId();
        videoManager.addSmallVideos(userId,videoFile,videoThumbnail);
    }

    @PostMapping("/smallVideos/{videoId}/like")//视频点赞
    public void videoLikes(@PathVariable String  videoId){
        Integer commentType=4;
        videoManager.videoLikes(videoId,commentType);
    }

    @PostMapping("/smallVideos/{videoId}/dislike")//视频取消点赞
    public void videoDisLikes(@PathVariable String videoId){
        Integer commentType=4;
        videoManager.videoDisLikes(videoId,commentType);
    }
    @GetMapping("/smallVideos/{videoId}/comments")//查询视频评论
    public ResponseEntity findVideoComments(@RequestParam(value = "page",defaultValue = "1") Integer pageNum,
                                            @RequestParam(value = "pagesize",defaultValue = "10") Integer pageSize,
                                            @PathVariable String videoId){
        Integer commentType=5;
        return videoManager.findVideoComments(videoId,pageNum,pageSize,commentType);
    }
    @PostMapping("/smallVideos/{videoId}/comments")//发布视频评论
    public void addVideoComments(@PathVariable String videoId,@RequestBody Map<String,String> map){
        String content = map.get("comment");
        Integer commentType=5;
        videoManager.addVideoComments(videoId,content,commentType);
    }
    @PostMapping("/smallVideos/comments/{contentId}/like")//视频评论点赞
    public void addVideoCommentsLike(@PathVariable String contentId){
        Integer commentType=6;
        videoManager.addVideoCommentsLike(contentId,commentType);
    }
    @PostMapping("/smallVideos/comments/{contentId}/dislike")//视频评论取消点赞
    public void delVideoCommentsLike(@PathVariable String contentId){
        Integer commentType=6;
        videoManager.delVideoCommentsLike(contentId,commentType);
    }



}
